Terrorism is, in the broadest sense, the use of intentional violence for political or religious purposes. It is used in this regard primarily to refer to violence during peacetime or in the context of war against non-combatants (mostly civilians and neutral military personnel). The terms "terrorist" and "terrorism" originated during the French Revolution of the late 18th century but gained mainstream popularity in the 1970s during the conflicts of Northern Ireland, the Basque Country and Palestine. The increased use of suicide attacks from the 1980s onwards was typified by the September 11 attacks in New York City and Washington, D.C. in 2001. There are various different definitions of terrorism, with no universal agreement about it. Terrorism is a charged term. It is often used with the connotation of something that is "morally wrong". Governments and non-state groups use the term to abuse or denounce opposing groups. Varied political organizations have been accused of using terrorism to achieve their objectives. These include right-wing and left-wing political organizations, nationalist groups, religious groups, revolutionaries and ruling governments. Legislation declaring terrorism a crime has been adopted in many states. When terrorism is perpetrated by nation states, it is not considered terrorism by the state conducting it, making legality a largely grey-area issue. There is no consensus as to whether or not terrorism should be regarded as a war crime.
source - wikipedia
from IPython.display import Image
Image("Terrorism.jpg",width = 1000, height = 300)
# Importing Libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import geopandas as gp
import datetime
import plotly.offline as py
import plotly.express as px
import plotly.figure_factory as ff
from plotly.offline import download_plotlyjs, init_notebook_mode, plot
from plotly.graph_objs import *
init_notebook_mode()
import warnings
warnings.filterwarnings("ignore")
# loading the dataset
dataset = pd.read_csv(r"globalterrorismdb_0718dist.csv",encoding='latin1')
dataset_shape = dataset.shape
dataset_columns = list(dataset.columns)
terror_df = dataset[['iyear','imonth','iday','country_txt','region_txt','provstate','city','latitude',
'longitude','success','attacktype1_txt','targtype1_txt','gname','weaptype1_txt','motive','nkill','nwound']]
# Renaming the columns
terror_df = terror_df.rename(columns={'iyear':'year',
'imonth': 'month',
'iday': 'day',
'country_txt': 'country',
'region_txt': 'region',
'provstate': 'state',
'attacktype1_txt': 'attackType',
'gname': 'groupName',
'targtype1_txt': 'target',
'weaptype1_txt': 'weaponType',
'nkill': 'kills',
'nwound': 'wounded'})
# digging deep into the data
print(terror_df.isnull().sum(),'\n\n')
print(terror_df.info(),'\n\n')
print(terror_df.describe(),'\n\n')
# Basic information from the data
print("Most Affected cities: ",end = '')
for i in terror_df['city'].value_counts().index[1:4]: print(i, end = '. ')
print('\n')
print("Countries under most terror (ascending): ", end = '')
for i in terror_df['country'].value_counts().index[0:3]: print(i, end = '. ')
print('\n')
print("Province/state under most terror (ascending): ", end='')
for i in terror_df['state'].value_counts().index[[0,1,3]]: print(i, end = '. ')
print('\n')
print("Year with most number of terror attacks:", terror_df['year'].value_counts().index[0], '\n')
print("Mostly used Weapon Type: ", terror_df['weaponType'].value_counts().index[0],'\n')
print("Most active attack groups: ", terror_df['groupName'].value_counts().index[1], '\n')
print("Mostly targeted are (ascending) : ", end = '')
for i in terror_df['target'].value_counts().index[0:3]: print(i, end='. ')
print("\n\nTotal number of Lives Losts in years due to terror attacks :", terror_df['kills'].sum())
year_wise = terror_df['year'].value_counts()
year_wise = pd.DataFrame(year_wise)
year_wise = year_wise.sort_index()
year_wise = year_wise.reset_index()
year_wise = year_wise.rename(columns={
'year': 'total_attacks', 'index': 'year'
})
# visualization of Year wise terror attacks
fig = px.line(year_wise, x="year", y="total_attacks", title = "Year wise number of terror Attack" )
fig.show()
Above plot shows that after 2010 the number of attacks increased with extremely high rate.
fig = plt.figure(figsize=(15,10))
sns.barplot(year_wise['year'],year_wise['total_attacks'], palette='gist_gray')
plt.xlabel("Year of the attacks")
plt.ylabel("Total Attacks")
plt.title("Year wise number of terror Attack")
plt.xticks(rotation = 45)
plt.show()
The growth in terror activities gradually grew untill 1992 after which it showed sign of decrease.
The growth in terror activities is seen again from 2004 where in 2014 most cases of terror attacks were reported
region_wise = terror_df['region'].value_counts()
region_wise = pd.DataFrame(region_wise)
region_wise = region_wise.reset_index()
region_wise = region_wise.rename(columns = {
'region': 'total_number_of_attacks', 'index': 'region'
})
top_region = region_wise
top_region
# visualization of Most affected region in world
plt.figure(figsize=(15,6))
sns.barplot(top_region['total_number_of_attacks'], top_region['region'],palette='gist_gray')
plt.ylabel("Region")
plt.xlabel("Total Attacks")
plt.title("Most Affected Region")
plt.show()
This shows that Middle East and North Africa followed by South Asia and South America are the most affected regions in the world
country_wise = terror_df['country'].value_counts()
country_wise = pd.DataFrame(country_wise)
#country_wise = country_wise.sort_index()
country_wise = country_wise.reset_index()
country_wise = country_wise.rename(columns = {
'country':'total_attacks', 'index':'country'
})
# displays top 30 most affected countries
top_30_countries = country_wise.head(30)
top_30_countries
# visualization of top 30 most affected countries
fig = px.bar(top_30_countries, x="country", y="total_attacks", color = "total_attacks", title = "30 country with most terror attacks" )
fig.update_layout(barmode='group', xaxis_tickangle=-45)
fig.show()
The above plot shows that Iraq, Pakistan and Afghanistan are most affected countries
city_wise = terror_df['city'].value_counts()
city_wise = pd.DataFrame(city_wise)
city_wise = city_wise.reset_index()
city_wise = city_wise.rename(columns = {
'city':'total_attacks', 'index':'city'
})
city_wise = city_wise.drop([0]) # dropped the "unknown" city from the data
from wordcloud import WordCloud
cities = city_wise['city'].head(30)
plt.subplots(figsize=(10,10))
wordcloud = WordCloud(background_color = 'black',
width = 1280,
height = 720).generate(' '.join(cities))
plt.axis('off')
plt.imshow(wordcloud)
plt.show()
# visualization of City wise terror attacks
top_30_cities = city_wise.head(30)
fig = px.bar(top_30_cities, x="city", y="total_attacks", color = "total_attacks", title = "30 cities with most terror attacks" )
fig.update_layout(barmode='group', xaxis_tickangle=-45)
fig.show()
The above bar plot shows that Baghdad, Karachi, Lima, and Mosul are cities that emerges as hotspot for the terror attacks.
terror_groups = terror_df['groupName'].value_counts()
terror_groups = pd.DataFrame(terror_groups)
terror_groups = terror_groups.reset_index()
terror_groups = terror_groups.rename(columns = {
'groupName': 'total_attacks', 'index': 'groups'
})
terror_groups = terror_groups.drop([0])
groups = terror_groups['groups'].head(30)
plt.subplots(figsize=(10,10))
wordcloud = WordCloud(background_color = 'black',
width = 1280,
height = 720).generate(' '.join(groups))
plt.axis('off')
plt.imshow(wordcloud)
plt.show()
# visualization of City wise terror attacks
top_30_terror_groups = terror_groups.head(30)
plt.figure(figsize=(15,10))
sns.barplot(top_30_terror_groups['total_attacks'], top_30_terror_groups['groups'], palette='gist_gray')
plt.ylabel("Terror Groups")
plt.xlabel("Total Attacks")
plt.title("30 Most Dangerous Groups")
plt.show()
The Taliban, ISIL and Shining Path are the top 3 terror groups that has carried most number of attack over the period of time of their presence
# success rate of the attacks
success_df = terror_df['success'].value_counts()
success_df = pd.DataFrame(success_df)
success_df = success_df.reset_index()
success_df = success_df.rename(columns = {
'sucess': 'total_number_of_sucess', 'index': 'efficiency'
})
# visualization of success rate of the attacks
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.axis('equal')
labels = ['Successful', 'Unsuccessful']
rate = success_df['success']
explode = (0, 0.1)
ax.pie(rate, labels = labels,explode = explode, shadow=True, startangle=90, autopct='%1.2f%%')
plt.show()
88.96% of times world fails to stop terror activites
# attack category
attack_category = terror_df['attackType'].value_counts()
attack_category = pd.DataFrame(attack_category)
attack_category = attack_category .reset_index()
attack_category = attack_category .rename(columns = {
'attackType': 'total_number_of_attack_used', 'index': 'attackType'
})
# dropping unknown
#attack_category = attack_category.drop([5])
# visualization of attack category
fig = px.pie(attack_category, values = "total_number_of_attack_used", names = "attackType", title = "Types of Attack carried out" )
fig.show()
The bombing/Explosion comprises around half of the terror activites followed by Armed Assault with 23.5% used attack category in the world
# Most Targetted group of People / Assest/ category
target_category = terror_df['target'].value_counts()
target_category = pd.DataFrame(target_category)
target_category = target_category.sort_index()
target_category = target_category .reset_index()
target_category = target_category .rename(columns = {
'target': 'total_number_of_times_got_attacked', 'index': 'targets'
})
# dropping unknown category
target_category=target_category.drop([19])
fig = plt.figure(figsize=(15,10))
sns.barplot(x='targets', y='total_number_of_times_got_attacked', data=target_category)
plt.xticks(rotation=70)
plt.tight_layout()
The above plot shows the targetted categories. Among them Private Citizens & Property along followed by Military and Police are most common targets.
import folium
# Shows the Map of the world with respect to terror atacks for a particular year
def world_year_map(year):
year_x = terror_df[terror_df['year'] == year][['latitude','longitude']]
year_x = year_x.dropna()
map_x = folium.Map(location =[0,0], tiles='cartodbpositron',zoom_start=2)
year_x.apply(lambda row:folium.Circle(location=[row["latitude"], row["longitude"]], radius=0, color = 'red' ).add_to(map_x), axis=1)
return map_x
world_year_map(2014)